#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include "lexer.h"
#include "error.h"
#include "parser.h"
#include "table.h"

using namespace std;
using namespace Error;
using namespace Lexer;
using namespace Parser;
using namespace Table;

int main(int argc,char* argv[])
{
	 table["pi"] = 3.1415926;
	 table["e"] = 2.7172818;  
	 cnt_of_errors = 0;
	 if (argc == 1) {
		 while (cin) {
			 Lexer::get_token(cin);
			 if (Lexer::curr_tok == Lexer::END) 	break;
			 if (Lexer::curr_tok == Lexer::PRINT) continue;
			 cout << "output:" << Parser::expr(false, cin) << endl;
		 }
	 }
	 else {
		 for (int I = 1; I < argc; I++) {
			 
			 cnt_of_errors = 0;
			 ifstream in(argv[I]);
			 while (in) {
				 get_token(in);
				 if (curr_tok == END) 	break;
				 if (curr_tok == PRINT) continue;
				 cnt_of_errors++;
				 cout << "output:" << Parser::expr(false, in) << endl;
			 }
		 }
	 }
	

	return Error::no_of_errors;
}
